<?php // viewgroup.php
$query1 = "select * from groups";
echo "<table id = 'teamtable' border = '1' align='center'>
			<thead><tr><th>Group ID</th><th>Group Name</th><th>Members</th></tr></thead><tbody>";
if($result = mysql_query($query1, $db)) {

	while($row = mysql_fetch_array($result)) {
		//print"<tr><td>";
		//print "<tr><td><input type='radio' name='choice' value=''/></td>";
		//echo "<td>{$row['idgroups']}</td><td>{$row['groupName']}</td>";
		echo "<tr><td>".$row['idgroups']."</td><td>".$row['groupName']."</td>" ;
		$query2 = "select name from students where idgroups = {$row['idgroups']}";
		$result2 = mysql_query($query2, $db);
		$strings ="";
		while ($row2 = mysql_fetch_array($result2))
		{
			$strings .= $row2['name'].',';
		}
		$membersName = substr($strings,0,-1);
		print "<td>{$membersName}</td></tr>";
		
	}
	
	//print "<tr><td align='center'><input type='checkbox' name='join' value=''/>Join";
	//print "<td align='center'><input type='checkbox' name='join' value=''/>Withdraw</td></tr>";
	//print "<tr><td align='center'><input TYPE='SUBMIT' VALUE='Submit' NAME='B1'></td></tr>";
	echo "</tbody></table>";

}
	else {
		print "<p>Could not retrieve the data because:<br/>".mysql_error($db).".</p>
		<p>The query being run was: ".$query. "</p>";
	}

	
	mysql_close($db); //close connection
?>